package cn.edu.neusoft.yuejian12.Activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import cn.edu.neusoft.yuejian12.Fragment.ClassInfoFragment;
import cn.edu.neusoft.yuejian12.Fragment.ClubInfoFragment;
import cn.edu.neusoft.yuejian12.Fragment.TvInfoFragment;
import cn.edu.neusoft.yuejian12.R;

/**
 * Created by 木子李 on 2017/10/18.
 */

public class ClubInfoActivity extends AppCompatActivity implements View.OnClickListener {
private LinearLayout mClub;
private LinearLayout mClass;
private LinearLayout mVideo;
private ImageView clublist_back;
private Fragment mTab6;
private Fragment mTab7;
private Fragment mTab8;
private ImageView clubinfo_pic;
private TextView clubinfo_name;
private Context mContext;


@Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.club_info);
        LinearLayoutManager LL = new LinearLayoutManager(this);
        initView();//初始化
        initEvent();//初始化事件
        showData();
        setSelect(0);//
        }

private void initEvent()
        {
        mClub.setOnClickListener(this);
        mClass.setOnClickListener(this);
        mVideo.setOnClickListener(this);
        clublist_back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
        finish();
        }
        });

        }

private void initView()
        {
        mClub = (LinearLayout) findViewById(R.id.clubinfo_club);
        mClass = (LinearLayout) findViewById(R.id.clubinfo_class);
        mVideo = (LinearLayout) findViewById(R.id.clubinfo_tv);
        clubinfo_pic = (ImageView) findViewById(R.id.club_info_pic);
        clubinfo_name = (TextView) findViewById(R.id.club_info_name);
        clublist_back = (ImageView) findViewById(R.id.clublist_back);

        }
private void showData(){
        Intent intent = getIntent();
        //String club_id = intent.getStringExtra("club_id");
        String club_name = intent.getStringExtra("club_name");
        String club_photo = intent.getStringExtra("club_photo");
        clubinfo_name.setText(club_name);
        String address="http://172.24.10.175/workout/Uploads/"+club_photo;
        Picasso.with(mContext).load(address).into(clubinfo_pic);
        }


private void setSelect(int i)
        {
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();
        hideFragment(transaction);

        switch (i)
        {
        case 0:
        if (mTab6 == null)
        {
        mTab6 = new ClubInfoFragment();
        transaction.add(R.id.id_content1, mTab6);
        } else
        {
        transaction.show(mTab6);
        }
        break;
       /* case 1:
        if (mTab7 == null)
        {
        mTab7 = new ClassInfoFragment()
        ;transaction.add(R.id.id_content1, mTab7);
        } else
        {
        transaction.show(mTab7);

        }
        break;
        case 2:
        if (mTab8 == null)
        {
        mTab8 = new TvInfoFragment();
        transaction.add(R.id.id_content1, mTab8);
        } else
        {
        transaction.show(mTab8);
        }
        break;*/
        }
        transaction.commit();
        }

private void hideFragment(FragmentTransaction transaction)
        {
        if (mTab6 != null)
        {
        transaction.hide(mTab6);
        }
        if (mTab7 != null)
        {
        transaction.hide(mTab7);
        }
        if (mTab8 != null)
        {
        transaction.hide(mTab8);
        }
        }

@Override
public void onClick(View v)
        {
        switch (v.getId())
        {
        case R.id.clubinfo_club:
        setSelect(0);
        break;
        case R.id.clubinfo_class:
        setSelect(1);
        break;
        case R.id.clubinfo_tv:
        setSelect(2);
        break;

default:
        break;
        }
        }

}
